Repository navigation
fix(engine,cli,producer): ffmpeg reading project media runs from an empty folder - #8832
Conversation
…mpty folder ffmpeg opens some names as written and resolves them against its working directory, which was the caller's, often a project folder. Inside `fromEmptyFolder` (@hyperframes/parsers/ff-binaries), ffmpeg and ffprobe spawned by the engine and by the CLI's media readers run from one empty temporary folder per process; outside it they keep the caller's folder. Each entry that opts in resolves its own paths first: - producer executeRenderJob (every local render: CLI render, studio server, producer server) - CLI captureSnapshots, describeProject, heardClips, and the check command's project-media inspection The guarded measure reads of a file a composition names also run from it, with the file resolved first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er and span renders The compile worker runs on its own thread, where the scope's store does not reach, so the parent passes whether it is inside one. A `--start/--end` render goes through renderSpan, now inside the scope with its paths resolved. The animated-GIF/HEIF cache folder is resolved like the frame cache, and the streaming encoder and audio pad/trim probe spawn from the scope's folder. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cope's wrappers main packs to 3738858 bytes, 807 under the 1% ceiling; the scope's wrappers add 1626 bytes across the producer's bundles. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Edit accuracy: accurate 273 (base branch 271), smooth 58 of thoseThe gate passes. Newly passing (2)
Not banked yet, reported and not gated (bank a full-grid run's baseline.json) (2)
Quarantined, measured but not gated (0) Unstable (1)
|
jrusso1020
left a comment
There was a problem hiding this comment.
Review at 3ccef59b: APPROVE.
- Delta since
1b1f16ba: one commit that only touchesscripts/package-size-budgets.json. It raises the producer's unpacked budget from 3702639 to 3740484 bytes; its packed budget stays 1065767. That is about 1.6 KB for the new wrappers over main's 3738858 bytes. No code changes.
What I checked:
- Scope wiring.
fromEmptyFolderis anAsyncLocalStoragescope, so concurrent renders in one server process each keep their own scope. Code outside the scope still getscwd: undefined, so library callers are unchanged. The compile worker gets the flag throughworkerDataand re-enters the scope, which is needed because the store doesn't cross threads. I checked the other workers: the shader-transition pool, lint, health and drawElement workers don't spawn ffmpeg on project media. - Paths inside the scope are absolute.
executeRenderJobandrenderSpanresolveprojectDirandoutputPath. The work folder is built from the resolved output path, or fromresolveRenderDebugDir(), which is absolute. The extract cache and the animated-GIF cache now resolve a relativeHYPERFRAMES_EXTRACT_CACHE_DIR. HLS-hls_segment_filenameisjoin(outputDir, …)off that resolved path.RenderConfighas no other path field that reaches ffmpeg (entryFileresolves against the project). No ffmpeg call in these paths writes into its working folder: I found no-pass,passlogfileor-report. That means the shared per-process folder stays empty. - CLI entries.
captureSnapshotsresolvesagainst.describeProjectandheardClipsresolve their roots. The measure guarded paths resolve before probing. - Tests, fails without the fix.
runFfmpeg.windowsHide.test.tspasses 2/2 at head. Removingcwd: ffmpegCwd()fromrunFfmpeg.tsandffprobe.tsmakes the new case fail.renderOrchestrator.emptyFolder.test.tspasses at head. Replacing thefromEmptyFolderwrapper with a plain call fails it:expected undefined to be defined.
Nits, not blocking:
absoluteLocalinaudio/analysis/decode.tsresolves outside the scope too. That is harmless, because it resolves against the same folder ffmpeg would have inherited.- If a tmp cleaner removes the folder,
ffmpegWorkingDir()makes a new one, and the exit hook only removes the latest. Only an empty folder is left behind, so this is fine.
Need · Size · Reuse · Simpler · Structure: completes the playlist-walk follow-up at the process level · +284/−70 · one helper in ff-binaries used by every spawner · a global process.chdir would hit every caller, so the scope is the right size · fine.
Risk: low to medium. A missed relative path inside a scoped entry would fail loudly as file-not-found, not silently. The Windows render job in CI covers the platform I didn't run.
— Rames
What
ffmpeg and ffprobe that read project media now run from an empty temporary folder, not the caller's working directory.
Why
ffmpeg opens some names as written, rather than joined to the folder of the file that names them. It resolves those names against its own working directory. That directory was inherited from the caller, which is often the project folder. Running from an empty folder means such a name finds nothing there.
Related work
This follows #8827, which made the playlist walk treat these names as leaving their folder. That PR makes the walk refuse them; this one makes sure the working directory they resolve against holds nothing.
How
@hyperframes/parsers/ff-binariesaddsfromEmptyFolder(work), anAsyncLocalStoragescope, andffmpegCwd().ffmpegCwd()returns one emptymkdtempfolder per process inside the scope, andundefinedoutside it.cwd: ffmpegCwd():runFfmpegrunFfmpegOnceexecuteRenderJob. Every local render goes through it: CLIrender(received projects included), the studio server, and the producer server. Desktop runs the CLI.--start/--endrenders throughrenderSpan.emptyFolderinworkerDataand the worker re-enters the scope.captureSnapshots. It also resolvesagainst.describeProjectandheardClips.HYPERFRAMES_EXTRACT_CACHE_DIRstill works inside a render.Size budget
@hyperframes/producer's unpacked budget goes up from 3702639 to 3740484 bytes.mainpacks to 3738858 bytes, 807 under the 1% ceiling, and the scope's wrappers add 1626 bytes across the producer's bundles. Its dependencies stay external, so nothing new is bundled.Not covered (these keep the inherited working directory)
renderChunk,assemble,plan,buildAudioSidecar. They run on Lambda or GCP from absolute/tmppaths, and their working directory is the task root, which holds no project content.Test plan
runFfmpeg.windowsHide.test.ts:runFfmpegandrunFfprobespawn with nocwdoutside the scope, and insidefromEmptyFolderwith an existing empty folder that is notprocess.cwd().cwdisundefinedinside the scope.renderOrchestrator.emptyFolder.test.ts: insideexecuteRenderJob, the compile stage seesffmpegCwd()as an empty folder, and it isundefinedagain afterwards.expected undefined to be defined. I checked this by removing the wrapper.runFfmpeg,ffprobe,configandvideoFrameExtractormeasure,snapshot,check,audio,timelineandcapture(1508 passed). The only failures are 2 Chromium WebGL tests: the local headless browser has no WebGL context, so they fail regardless of this change.renderOrchestrator*,captureHdr*and the bun-run media prep teststscfor parsers, engine, cli and producerbun run lintand the comment ratchet🤖 Generated with Claude Code